package com.immunology.service;

import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

public abstract class RegistrationValidService {

	protected static final String WRONG_PARAMETER = "Wrong!";
	protected static final String PASSWORD_MUST_BE_SAME = "Password must be the same!";

	public Map<String, String> map = null;

	public Map<String, String> getErrorMap() {
		return map;
	}

	abstract Map<String, String> parametersValidation(
			Map<String, String> parameters);

	public boolean isValid(Map<String, String> parameters) {
		boolean result = true;
		parametersValidation(parameters);
		if (map.containsValue(WRONG_PARAMETER)) {
			result = false;
		}
		return result;
	}

	protected Map<String, String> setNotNullParameters(
			Map<String, String> parameters) {
		Map<String, String> erorParameters = new TreeMap<String, String>();
		Iterator<String> iterator = parameters.keySet().iterator();
		while (iterator.hasNext()) {
			String key = iterator.next();
			String value = parameters.get(key);
			if (value.isEmpty()) {
				erorParameters.put(key, WRONG_PARAMETER);
			} else {
				erorParameters.put(key, value);
			}
		}
		return erorParameters;
	}
}
